<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.ByteArrayOutputStream" %>
<%@ page import="weaver.file.ImageFileManager" %>
<%@ page import="java.util.Base64" %>
<%
    out.println("start." + "<br>");

            int imageId = 206372;
            out.println("imageFileId is:" + imageId + "<br>");

        String base64 = "";
        // 读取图片字节数组
        InputStream in = null;
        ByteArrayOutputStream out1 = null;
    try {
            //weaver.file.ImageFileManager#getInputStreamById 直接这个就能获取文件流
            in = ImageFileManager.getInputStreamById(imageId);
            out1 = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            int bytesRead = -1;
            while ((bytesRead = in.read(buffer)) != -1) {
                out1.write(buffer, 0, bytesRead);
            }
            byte[] imageBytes = out1.toByteArray();
            base64 = Base64.getEncoder().encodeToString(imageBytes);
        } catch (Exception e) {
            out.println("error is:" + e + "<br>");
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out1.close();
            }
        }
            out.println("imageBase64 is:" + base64 + "<br>");

    out.println("end." + "<br>");
%>